﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System;
using System.Reflection;

namespace BrainTechLLC
{
    public static class Notification_RegisterTypes
    {
        public static Type[] RegisterTypes()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            DLLContents contents = TypeProvider.GetInstance().GetDLLContents(assembly.FullName);
            var types = assembly.GetTypes();
            types.ForEach(type =>
            {
                if (type.IsTypeOkay())
                    TypeProvider.GetInstance().AddType(contents, type);
            });
            return types;
        }
    }

    /// <summary>
    /// Base class for Notifications... may not be needed - rethink
    /// </summary>
    [Serializable]
    public class Notification : INotificationMessage, IPerformsInitialization
    {
        // TODO - better place for this static initialization code... some way to use reflection on all assemblies in silverlight?
        public static void RegisterMessageSerializationTypes()
        {
            ByteDataMessage.Register();
            NumericMessage.Register();
            StringMessage.Register();
            NotificationMessageText.Register();
            StringAndNumeric.Register();
            TwoStringsAndTwoNumerics.Register();
            NotificationMessageTextWithSource.Register();
        }

        static Notification()
        {
            RegisterMessageSerializationTypes();
        }

        public Notification()
        {
        }

        public Notification(object o)
        {
            NotificationObject = o;
        }

        public object NotificationObject { get; set; }

        #region IPerformsInitialization Members

        public string[] DependencyTypeNames
        {
            get { return null; }
        }

        public int RequestedOrder
        {
            get { return 1; }
        }

        public int Priority
        {
            get { return 1; }
        }

        public bool Initialize(ITypeLookup typeLookup)
        {
            RegisterMessageSerializationTypes();
            return true;
        }

        #endregion
    }
}